<?php
require_once ROOT_APPLICATION_MODULES_ADMIN_MODELS.DS."Categorys.php";
require_once ROOT_LIBRARY_UTILITY.DS."Converter.php";

class Zend_View_Helper_ShowArticle{
    public function showArticle($view, $article) {
		
    	$str='';
    	$str.= '<div id="';
    	$str.= 'article_' . $article->article_id;
    	$str.= '" class="article">';
			$str.="<h2>";
			$str.=  '<a href="' . $view->url(array('controller'=>'article', 'action'=>'view', 'article_id'=>$article->article_id)) . '">' . $article->title . '</a>';
			$str.= "</h2>";
			
			$str.= "<small>";
			
			$str.= '<div class="writedate">';
			$str.= $article->created_date;
			$str.= "</div>";
			
			$str.= '<div class="description">';
			$str.= 'Writer: ';
			$str.= '<b>' . $article->author . '</b>';
			$str.= ' | ';
			$category_model = new End_Models_Categorys();
			if($article->category_id == null)
				$article->category_id = 1;
			$category = $category_model->find($article->category_id);
			
			$str.=  'Directory: ';
			$category_array = Utility_Converter::objectToArray($category);
			$str.= '<a class="category_link" href="' . $view->url(array('controller'=>'category', 'action'=>'view', 'category_id'=>$article->category_id)) . '">' . '<b>' . $category_array[0]->name . '</b>' . '</a>' ;  
			$str.= "</div>";
			$str.= "</small>";
			
			$str.= '<div class="entry">';
			$limited_content = '';
			$full_content = $article->content;
			$limited_content = substr($full_content, 0, DEFAULT_MAX_ARTICLE_CHARS);
			$last_pos = strrpos($limited_content, ' ');
			if($last_pos != false)
				$limited_content = substr($limited_content, 0, $last_pos);
			$limited_content = strip_tags($limited_content, DEFAULT_ALLOWED_TAGS);
			$limited_content .= '...' . '<a class="read_more" href="' . $view->url(array('controller'=>'article', 'action'=>'view', 'article_id'=>$article->article_id)) . '">Read more</a>';
			// $limited_content = $article->description;
			$str.= $limited_content;
			$str.= "</div>";
		$str .= '</div>';	
		
		
        return $str; 

    }
}